package com.carleasoft.mps.core.utils;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.*;

/**
 * <p>Description: 时间工具类</p>
 * @since 2020/4/28
 * @author wangxiao
 */
public class DateUtil {

    /**
     * 仅显示年月日，例如 2020-01-01
     */
    public static final String DATE_FORMAT_1 = "yyyy-MM-dd";

    /**
     * 仅显示年月日，例如 2020/01/01
     */
    public static final String DATE_FORMAT_2 = "yyyy/MM/dd";

    /**
     * 仅显示年月日，例如 20200101
     */
    public static final String DATE_FORMAT_3 = "yyyyMMdd";

    /**
     * 仅显示时分秒，例如 00:00:00
     */
    public static final String TIME_FORMAT_1 = "HH:mm:ss";

    /**
     * 仅显示时分秒，例如 000000
     */
    public static final String TIME_FORMAT_2 = "HHmmss";

    /**
     * 显示年月日时分，例如 2020-01-01 00:00
     */
    public static final String DATETIME_FORMAT_1 = "yyyy-MM-dd HH:mm";

    /**
     * 显示年月日时分，例如 2020/01/01 00:00
     */
    public static final String DATETIME_FORMAT_2 = "yyyy/MM/dd HH:mm";

    /**
     * 显示年月日时分秒，例如 2020-01-01 00:00:00
     */
    public static final String DATETIME_FORMAT_3 = "yyyy-MM-dd HH:mm:ss";

    /**
     * 显示年月日时分秒，例如 2020/01/01 00:00:00
     */
    public static final String DATETIME_FORMAT_4 = "yyyy/MM/dd HH:mm:ss";

    /**
     * 每天的毫秒数 8640000
     */
    public static final long MILLISECONDS_PER_DAY = 86400000L;

    /**
     * 每周的天数
     */
    public static final long DAYS_PER_WEEK = 7L;

    /**
     * 每小时毫秒数
     */
    public static final long MILLISECONDS_PER_HOUR = 3600000L;

    /**
     * 每分钟秒数
     */
    public static final long SECONDS_PER_MINUTE = 60L;

    /**
     * 每小时秒数
     */
    public static final long SECONDS_PER_HOUR = 3600L;

    /**
     * 每天秒数
     */
    public static final long SECONDS_PER_DAY = 86400L;

    /**
     * 每个月秒数，默认每月30天
     */
    public static final long SECONDS_PER_MONTH = 2592000L;

    /**
     * 每年秒数，默认每年365天
     */
    public static final long SECONDS_PER_YEAR = 31536000L;

    /**
     * 常用时间格式
     */
    private static final String[] parsePatterns = {DATE_FORMAT_1, DATE_FORMAT_2, DATE_FORMAT_3,
            TIME_FORMAT_1, TIME_FORMAT_2,
            DATETIME_FORMAT_1, DATETIME_FORMAT_2, DATETIME_FORMAT_3, DATETIME_FORMAT_4};

    public static String[] weekOfDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};

    public static Integer[] hebdom = {7,1, 2, 3, 4, 5, 6};

    /**
     * 获取当前时间的毫秒数
     * @return 当前时间的毫秒数
     */
    public static long getCurrentTime() {
        return new Date().getTime();
    }

    /**
     * 将日期型字符串转换为毫秒数
     * 支持的日期字符串格式包括 "yyyy-MM-dd", "yyyy/MM/dd", "yyyyMMdd", "HH:mm:ss", "HHmmss", "yyyy-MM-dd HH:mm", "yyyy/MM/dd HH:mm", "yyyy-MM-dd HH:mm:ss", "yyyy/MM/dd HH:mm:ss"
     * @param str 要进行转换的日期字符串
     * @return long
     */
    public static long getMillisecond(String str) {
        long millis = 0;
        if(StringUtils.isNotBlank(str)) {
            millis = parseDate(str).getTime();
        }
        return millis;
    }

    /**
     * 获取当前日期的字符串，例如 2020-01-01
     * @return
     */
    public static String getDate() {
        return getDate(DateUtil.DATE_FORMAT_1);
    }

    /**
     * 获取指定格式的时间字符串
     * @param pattern
     * @return
     */
    public static String getDate(String pattern) {
        return getDate(new Date(), pattern);
    }

    /**
     * 按指定格式格式化指定的毫秒数
     * @param millis 需要格式化的时间毫秒数
     * @param pattern 时间格式
     * @return
     */
    public static String getDate(long millis, String pattern) {
        return getDate(new Date(millis), pattern);
    }

    /**
     * 按指定格式格式化指定的时间
     * @param date 需要格式化的时间
     * @param pattern 时间格式
     * @return
     */
    public static String getDate(Date date, String pattern) {
        return DateFormatUtils.format(date, pattern);
    }

    /**
     * 获取当前时间的字符串，例如 2020-01-01 00:00:00
     * @return 当前时间的字符串
     */
    public static String getCurrentTimeStr() {
        return DateFormatUtils.format(new Date(), DATETIME_FORMAT_3);
    }

    /**
     * 获取当前时间的指定格式的时间字符串
     * @return
     */
    public static String getTimeStr(String pattern) {
        return getTimeStr(new Date(), pattern);
    }

    /**
     * 将指定的毫秒数转换为指定格式的时间字符串
     * @param millis
     * @param pattern
     * @return
     */
    public static String getTimeStr(long millis, String pattern) {
        return getTimeStr(new Date(millis), pattern);
    }

    /**
     * 将指定的日期对象转换为指定格式的时间字符串
     * @param date
     * @param pattern
     * @return
     */
    public static String getTimeStr(Date date, String pattern) {
        return DateFormatUtils.format(date, pattern);
    }

    /**
     * 将日期字符串转换为日期对象
     * 支持的日期字符串格式包括 "yyyy-MM-dd", "yyyy/MM/dd", "yyyyMMdd", "HH:mm:ss", "HHmmss", "yyyy-MM-dd HH:mm", "yyyy/MM/dd HH:mm", "yyyy-MM-dd HH:mm:ss", "yyyy/MM/dd HH:mm:ss"
     * @param str 要进行转换的日期字符串
     * @return Date
     */
    public static Date parseDate(String str) {
        Date date = null;
        if(StringUtils.isNotBlank(str)) {
            try {
                date = DateUtils.parseDate(str, parsePatterns);
            }catch(ParseException e) {
                e.printStackTrace();
            }
        }
        return date;
    }

    /**
     * 获取当前年份字符串
     * @return String 当前年份字符串，例如 2020
     */
    public static String getYear() {
        return getTimeStr(new Date(), "yyyy");
    }

    /**
     * 获取当前月份字符串
     * @return String 当前月份字符串，例如 01
     */
    public static String getMonth() {
        return getTimeStr(new Date(), "MM");
    }

    /**
     * 获取当前天数字符串
     * @return String 当前天数字符串，例如 01
     */
    public static String getDay() {
        return getTimeStr(new Date(), "dd");
    }

    /**
     * 获取当前星期字符串
     * @return String 当前星期字符串，例如星期一
     */
    public static String getWeek() {
        return getTimeStr(new Date(), "E");
    }

    /**
     * 获取指定日期字符串是星期几
     * @param dateStr 日期
     * @return 星期几
     */
    public static String getDayOfWeek(String dateStr) {
        Date date = parseDate(dateStr);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int num = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        return weekOfDays[num];
    }


    /**
     * 获取指定日期字符串是星期几
     * @param dateStr 日期
     * @return 星期几
     */
    public static String getDayOfWeek(LocalDate dateStr) {
        DateTimeFormatter dfDate = DateTimeFormatter.ofPattern("yyyy/MM/dd");
        String format = dfDate.format(dateStr);
        Date date = parseDate(format);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int num = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        return weekOfDays[num];
    }

    /**
     * 获取指定日期字符串是星期几
     * @param dateStr 日期
     * @return 星期几
     */
    public static Integer getDayOfIndex(LocalDate dateStr) {
        DateTimeFormatter dfDate = DateTimeFormatter.ofPattern("yyyy/MM/dd");
        String format = dfDate.format(dateStr);
        Date date = parseDate(format);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(Calendar.DAY_OF_WEEK) - 1;
    }

    /**
     * 获取指定日期是星期几
     * @param date 日期
     * @return 星期几
     */
    public static String getDayToWeek(Date date) {

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int num = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        return weekOfDays[num];
    }

    /**
     * 获取指定日期是星期几
     * @param dateStr 日期
     * @return 星期几
     */
    public static Integer getDayToWeek(String dateStr) {
        Date date = parseDate(dateStr);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int num = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        return hebdom[num];
    }

    /**
     * 获取指定日期是星期几
     * @param date 日期
     * @return 星期几
     */
    public static Integer getDayToInt(LocalDate date) {
        Calendar calendar = Calendar.getInstance();
        DateTimeFormatter dfDate = DateTimeFormatter.ofPattern("yyyy/MM/dd");
        String format = dfDate.format(date);
        Date time = parseDate(format);
        calendar.setTime(time);
        int num = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        return hebdom[num];
    }

    /**
     * 查询消失之后的时间
     * @return
     */
    public static String getAfterSpecifiedHour(String dateStr,Integer hour){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        format.setTimeZone(TimeZone.getTimeZone("GMT+0"));
        Date date = null;
        try {
            date = format.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        format.setTimeZone(TimeZone.getTimeZone("GMT+"+hour));
        return format.format(date);
    }

    /**
     * 查询消失之前的时间
     * @return
     */
    public static String getBeforeSpecifiedHour(String dateStr,Integer hour){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        format.setTimeZone(TimeZone.getTimeZone("GMT+"+hour));
        Date date = null;
        try {
            date = format.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        format.setTimeZone(TimeZone.getTimeZone("GMT+0"));
        return format.format(date);
    }



    /**
     * 获取当前日期指定天数之后的日期
     * @param num 相隔天数
     * @return Date 日期
     */
    public static Date nextDay(int num) {
        Calendar curr = Calendar.getInstance();
        curr.set(Calendar.DAY_OF_MONTH, curr.get(Calendar.DAY_OF_MONTH) + num);
        return curr.getTime();
    }

    /**
     * 获取当前日期指定天数之后的日期
     * @param num 相隔天数
     * @return Date 日期
     */
    public static Date lastDay(int num,LocalDate now) {
        Calendar curr = Calendar.getInstance();
        DateTimeFormatter dfDate = DateTimeFormatter.ofPattern("yyyy/MM/dd");
        String format = dfDate.format(now);
        Date specifiedDate = parseDate(format);
        curr.setTime(specifiedDate);
        curr.set(Calendar.DAY_OF_MONTH, curr.get(Calendar.DAY_OF_MONTH) - num);
        return curr.getTime();
    }

    /**
     * 获取当前日期指定月数之后的日期
     * @param num 间隔月数
     * @return Date 日期
     */
    public static Date nextMonth(int num,LocalDate now) {
        Calendar curr = Calendar.getInstance();
        DateTimeFormatter dfDate = DateTimeFormatter.ofPattern("yyyy/MM/dd");
        String format = dfDate.format(now);
        Date specifiedDate = parseDate(format);
        curr.setTime(specifiedDate);
        curr.set(Calendar.MONTH, curr.get(Calendar.MONTH) + num);
        return curr.getTime();
    }

    /**
     * 获取当前日期指定月数之后的日期
     * @param num 间隔月数
     * @return Date 日期
     */
    public static Date lastMonth(int num) {
        Calendar curr = Calendar.getInstance();
        curr.set(Calendar.MONTH, curr.get(Calendar.MONTH) + num);
        return curr.getTime();
    }

    /**
     * 获取当前日期指定年数之后的日期
     * @param num 间隔年数
     * @return Date 日期
     */
    public static Date nextYear(int num) {
        Calendar curr = Calendar.getInstance();
        curr.set(Calendar.YEAR, curr.get(Calendar.YEAR) + num);
        return curr.getTime();
    }

    /**
     * 计算两个日期之前间隔的小时数
     * @param start 开始时间
     * @param end 结束时间
     * @return String 相差的小时数，保留一位小数
     */
    public static String dateMinus(Date start, Date end) {
        if(start == null || end == null) {
            return "0";
        }
        Long r = end.getTime() - start.getTime();
        DecimalFormat df = new DecimalFormat("#.0");
        double result = r * 1.0 / DateUtil.MILLISECONDS_PER_HOUR;
        return df.format(result);
    }

    /**
     * 获取当前日期与指定日期相隔的天数
     * @param date 给定的日期
     * @return long 日期间隔天数，正数表示给定日期在当前日期之前，负数表示在当前日期之后
     */
    public static long pastDays(Date date) {
        return getDaysBetween(date, new Date());
    }

    /**
     * 计算两个日期之间相差天数.
     * @param start 开始日期
     * @param end   结束日期
     * @return long 相隔天数
     */
    public static long getDaysBetween(Date start, Date end) {
        long diff = 0;
        if(start != null && end != null) {
            diff = (end.getTime() - start.getTime()) / DateUtil.MILLISECONDS_PER_DAY;
        }
        return diff;
    }

    /**
     * 计算两个日期之前相隔多少周.
     * @param start 计算开始时间
     * @param end   计算结束时间
     * @return long 相隔周数，向下取整
     */
    public static long getWeeksBetween(Date start, Date end) {
        return getDaysBetween(start, end) / DateUtil.DAYS_PER_WEEK;
    }

    /**
     * 两个日期相隔的月份
     * @param startDate 开始日期
     * @param endDate   结束日期
     * @return
     */
    public static int getMonthsBetween(String startDate, String endDate) {
        Calendar c1 = Calendar.getInstance();
        Calendar c2 = Calendar.getInstance();
        c1.setTime(parseDate(startDate));
        c2.setTime(parseDate(endDate));
        int year = c2.get(Calendar.YEAR) - c1.get(Calendar.YEAR);
        int month = c2.get(Calendar.MONTH) - c1.get(Calendar.MONTH);
        return Math.abs(year * 12 + month);
    }

    /**
     * 获取指定日期间隔给定天数后的日期
     * @param specifiedDay 给定的字符串格式日期，支持的日期字符串格式包括
     *        "yyyy-MM-dd", "yyyy/MM/dd", "yyyyMMdd", "HH:mm:ss", "HHmmss", "yyyy-MM-dd HH:mm", "yyyy/MM/dd HH:mm", "yyyy-MM-dd HH:mm:ss", "yyyy/MM/dd HH:mm:ss"
     * @param num 间隔天数
     * @return String 间隔指定天数之后的日期的字符串
     */
    public static String getSpecifiedDayAfter(String specifiedDay, int num) {
        Date specifiedDate = parseDate(specifiedDay);
        Calendar c = Calendar.getInstance();
        c.setTime(specifiedDate);
        int day = c.get(Calendar.DATE);
        c.set(Calendar.DATE, day + num);
        return getTimeStr(c.getTime(), DateUtil.DATETIME_FORMAT_3);
    }
    /**
     * 获取指定日期间隔给定天数后的日期
     * @param specifiedDay 给定的字符串格式日期，支持的日期字符串格式包括
     *        "yyyy-MM-dd", "yyyy/MM/dd", "yyyyMMdd", "HH:mm:ss", "HHmmss", "yyyy-MM-dd HH:mm", "yyyy/MM/dd HH:mm", "yyyy-MM-dd HH:mm:ss", "yyyy/MM/dd HH:mm:ss"
     * @param num 间隔天数
     * @return String 间隔指定天数之后的日期的字符串
     */
    public static String getSpecifiedDayAfter(LocalDate specifiedDay, int num) {
        DateTimeFormatter dfDate = DateTimeFormatter.ofPattern("yyyy/MM/dd");
        String format = dfDate.format(specifiedDay);
        Date specifiedDate = parseDate(format);
        Calendar c = Calendar.getInstance();
        c.setTime(specifiedDate);
        int day = c.get(Calendar.DATE);
        c.set(Calendar.DATE, day + num);
        return getTimeStr(c.getTime(), DateUtil.DATETIME_FORMAT_3);
    }


    /**
     * 获取指定日期间隔给定天数后的日期
     * @param specifiedDay 给定的字符串格式日期，支持的日期字符串格式包括
     *        "yyyy-MM-dd", "yyyy/MM/dd", "yyyyMMdd", "HH:mm:ss", "HHmmss", "yyyy-MM-dd HH:mm", "yyyy/MM/dd HH:mm", "yyyy-MM-dd HH:mm:ss", "yyyy/MM/dd HH:mm:ss"
     * @param num 间隔天数
     * @return String 间隔指定天数之后的日期的字符串
     */
    public static String getSpecifiedDayBefore(LocalDate specifiedDay, int num) {
        DateTimeFormatter dfDate = DateTimeFormatter.ofPattern("yyyy/MM/dd");
        String format = dfDate.format(specifiedDay);
        Date specifiedDate = parseDate(format);
        Calendar c = Calendar.getInstance();
        c.setTime(specifiedDate);
        int day = c.get(Calendar.DATE);
        c.set(Calendar.DATE, day - num);
        return getTimeStr(c.getTime(), DateUtil.DATETIME_FORMAT_3);
    }


    /**
     * 将 Date 日期转化为 Calendar 类型日期
     * @param date 给定的时间，若为null，则默认为当前时间
     * @return Calendar Calendar对象
     */
    public static Calendar getCalendar(Date date) {
        Calendar calendar = Calendar.getInstance();
        //每周从周一开始
        calendar.setFirstDayOfWeek(Calendar.MONDAY);
        // 设置每周最少为1天
        // calendar.setMinimalDaysInFirstWeek(1);
        if(date != null) {
            calendar.setTime(date);
        }
        return calendar;
    }

    /**
     * 将以秒为单位的时间转换为其他单位
     * @param seconds 秒数
     * @return String 例如 16分钟前、2小时前、3天前、4月前、5年前等
     */
    public static String getIntervalBySeconds(long seconds) {
        StringBuffer buffer = new StringBuffer();
        if(seconds < SECONDS_PER_MINUTE) {
            buffer.append(seconds).append("秒前");
        }else if(seconds < SECONDS_PER_HOUR) {
            buffer.append(seconds / SECONDS_PER_MINUTE).append("分钟前");
        }else if(seconds < SECONDS_PER_DAY) {
            buffer.append(seconds / SECONDS_PER_HOUR).append("小时前");
        }else if(seconds < SECONDS_PER_MONTH) {
            buffer.append(seconds / SECONDS_PER_DAY).append("天前");
        }else if(seconds < SECONDS_PER_YEAR) {
            buffer.append(seconds / SECONDS_PER_MONTH).append("月前");
        }else {
            buffer.append(seconds / DateUtil.SECONDS_PER_YEAR).append("年前");
        }
        return buffer.toString();
    }

    /**
     * 指定的时间相对于当前时间过去了多久
     * @param createTime
     * @return
     */
    public static String getNowTimeBefore(long createTime) {
        long now = System.currentTimeMillis() / 1000;
        long differ = now - createTime / 1000;
        String dateStr = "";
        if(differ <= 60) {
            dateStr = "刚刚";
        }else if(differ <= 3600) {
            dateStr = (differ / 60) + "分钟前";
        }else if(differ <= 3600 * 24) {
            dateStr = (differ / 3600) + "小时前";
        }else if(differ <= 3600 * 24 * 30) {
            dateStr = (differ / (3600 * 24)) + "天前";
        }else {
            getDate(DATE_FORMAT_1);
        }
        return dateStr;
    }

    /**
     * 判断当前日期是否是周末
     * @return
     */
    public static boolean isWeekend() {
        Date date = new Date();
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        return cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY;
    }

    /**
     * 判断当前日期是否是周一
     * @return
     */
    public static boolean isMONDAY(LocalDate data){
        Calendar cal = Calendar.getInstance();
        DateTimeFormatter dfDate = DateTimeFormatter.ofPattern("yyyy/MM/dd");
        String format = dfDate.format(data);
        Date specifiedDate = parseDate(format);
        cal.setTime(specifiedDate);
        return cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY;
    }

    /**
     * 根据指定之间获得星期一
     * @param data
     */
    public static LocalDate getMONDAY(LocalDate data) {
        Calendar cal = Calendar.getInstance();
        DateTimeFormatter dfDate = DateTimeFormatter.ofPattern("yyyy/MM/dd");
        String format = dfDate.format(data);
        Date specifiedDate = parseDate(format);;
        cal.setTime(specifiedDate);
        int day = hebdom[cal.get(Calendar.DAY_OF_WEEK) - 1];
        return LocalDate.parse(DateUtil.getSpecifiedDayBefore(data, day - 1).split(" ")[0]);
    }

    /**
     * 判断当前日期是否是周末
     * @return
     */
    public static boolean isDay() {
        Date date = new Date();
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        return cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY;
    }

    /**
     * 获取日期yyyy-MM-dd格式字符串
     *
     * @param date
     * @param locale
     * @return
     */
    public static String dateToStr(Date date, Locale locale) {
        if (locale == null) {

        }
        return chinaDateSDF.get().format(date);
    }

    /**
     * 将长时间格式字符串转换为时间 yyyy-MM-dd HH:mm:ss
     *
     * @param strDate
     * @return
     */
    public static Date strToDateLong(String strDate) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        ParsePosition pos = new ParsePosition(0);
        Date strtodate = formatter.parse(strDate, pos);
        return strtodate;
    }

    public static Long getHours(String duration){
        String[] time = duration.split(":");
        int hour = 0;
        int min = 0;
        double sec;
        if (time.length == 3){
            hour = Integer.parseInt(time[0]);
            min = Integer.parseInt(time[1]);
            sec = Integer.parseInt(time[2]);
        }else if (time.length == 2){
            min = Integer.parseInt(time[0]);
            sec = Integer.parseInt(time[1]);
        }else {
            BigDecimal bigDecimal = new BigDecimal(time[0]).setScale(0,BigDecimal.ROUND_DOWN);
            sec =Double.parseDouble(bigDecimal.toString());
        }
        return (long)(hour* 3600L +min* 60L +sec);
    }

    public static ThreadLocal<DateFormat> chinaDateSDF = new ThreadLocal<DateFormat>() {

        @Override
        protected DateFormat initialValue() {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
            return df;

        }
    };

    public static Long getEpochSecond(){
       return LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
    }

    public static Boolean isTimeRange(String time){
        LocalDateTime localDateTime = LocalDateTime.now();
        int newHour = localDateTime.getHour();
        int newMinute = localDateTime.getMinute();

        String[] split = time.split(":");
        int oldHour = Integer.parseInt(split[0]);
        int oldMinute = Integer.parseInt(split[1]);
        //在当前时间之前
        int hour = newHour - oldHour;
        int minute = newMinute - oldMinute;
        if (hour > 0){
            return true;
        }else if (hour < 0){
            return false;
        }else {
           if (minute >= 0){
               return true;
           }else {
               return false;
           }
        }
    }




}
